package com.sgb.kjwl.viewmodel.machine;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.self.LeaseInquiryCountEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.self.UserInquiryEntity;
import com.sgb.kjwl.repository.MachineRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.fragment.self.MyInquiryLeaseFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyInquiryLeaseFragModel extends BaseViewModel {

    private MyInquiryLeaseFragment leaseFragment;
    private MachineRepertory repertory;

    public MyInquiryLeaseFragModel(MyInquiryLeaseFragment leaseFragment, MachineRepertory repertory) {
        this.leaseFragment = leaseFragment;
        this.repertory = repertory;
    }

    //获取类型
    public void getFilterTypeModel(String type) {
        APIManager.getInstance().getInquiryAPI().getInquiryType(type).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                leaseFragment.showClassTypeList(data.getData());
            }
        });

    }

    //发起的函询
    public void getDataListMyInquiry(String classNo, String statusNo, String modelType, int page) {
        Map map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", 10);
        map.put("modelType", modelType);
        map.put("markType", classNo);//租赁类型1 设备 ；2 机械，3车辆； 4 房产，5土地，6 工厂 全部""
        map.put("state", statusNo); //全部"" 已回复5 未回复1
        APIManager.getInstance().getInquiryAPI().getMyInquiry(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<UserInquiryEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<UserInquiryEntity>>> data) {
                leaseFragment.showList(data.getData().getList());
            }
        });
    }

    //收到的函询
    public void getDataListMyReplay(String classNo, String statusNo, String modelType, int page) {
        Map map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", 10);
        map.put("modelType", modelType);//业务类型 (4出租 5求租 6报价)
        map.put("markType", classNo);//租赁类型1 设备 ；2 机械，3车辆； 4 房产，5土地，6 工厂 全部""
        map.put("state", statusNo); //全部"" 已回复5 未回复1
        DialogHelper.showProgressDialog(leaseFragment.getActivity(), null, "加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getInquiryAPI().getMyReplay(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<UserInquiryEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<UserInquiryEntity>>> data) {
                leaseFragment.showList(data.getData().getList());
            }
        });
    }

    //函询数量统计
    public void getCount() {
        APIManager.getInstance().getInquiryAPI().getEnquireCount().enqueue(new ICallBack<BaseEntity<LeaseInquiryCountEntity>>() {
            @Override
            public void onSuccess(BaseEntity<LeaseInquiryCountEntity> data) {
                LeaseInquiryCountEntity entity = data.getData();
                leaseFragment.showCount(entity);
            }
        });
    }

    //函询详情H5
    public void getH5Url(String id, int type) {
        APIManager.getInstance().getPickAPI().getUrlSetting("replyDetails").enqueue(new ICallBack<BaseEntity<H5ReEntity>>(true) {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                //inquiryType  1 是收到， 2是发起
                String url = data.getData().getUrl() + "?id=" + id + "&inquiryType=" + type + 1;
                WebViewX5HostActivity.start(leaseFragment.getActivity(), url);
            }
        });
    }

}
